#include "GameTime.h"


GameTime::GameTime(void) : _deltaTime(0.0f){}
GameTime::~GameTime(void){}

GameTime* GameTime::_instance = nullptr;

GameTime* GameTime::getSingleton()
{
	if (_instance == nullptr)
	{
		_instance = new GameTime();
	}
	return _instance;
}

void GameTime::cleanSingleton()
{
	if (_instance !=  nullptr)
	{
		delete _instance;
		_instance = nullptr;
	}
}

void GameTime::update()
{
	_totalTime = _totalTimeClock.getElapsedTime();
	_elapsedTime = _elapsedTimeClock.restart();
	_deltaTime = static_cast<float>(_elapsedTime.asMilliseconds()) / 1000.0f;
	if (_deltaTime > 0.1f)
		_deltaTime = 0.0f;
}

float GameTime::getTotalTimeAsSeconds() const
{
	return _totalTime.asSeconds();
}

sf::Int32 GameTime::getTotalTimeAsMilliseconds() const
{
	return _totalTime.asMilliseconds();
}

sf::Int64 GameTime::getTotalTimeAsMicroseconds() const
{
	return _totalTime.asMicroseconds();
}

float GameTime::getElapsedTimeAsSeconds() const
{
	return _elapsedTime.asSeconds();
}

sf::Int32 GameTime::getElapsedTimeAsMilliseconds() const
{
	return _elapsedTime.asMilliseconds();
}

sf::Int64 GameTime::getElapsedTimeAsMicroseconds() const
{
	return _elapsedTime.asMicroseconds();
}

float GameTime::deltaTime() const
{
	return _deltaTime;
}